package ms.jasim.framework.reaction;

import ms.jasim.framework.ICustomEventReaction;
import ms.jasim.framework.IEventSimulationInfoProvider;
import ms.jasim.framework.IJasimAppContext;
import ms.jasim.framework.SolutionSimulator;
import ms.jasim.model.JasimModel;
import ms.jasim.model.event.CustomReaction;
import ms.jasim.model.event.Event;

public class CheckModelConsistent implements ICustomEventReaction {

	@Override
	public boolean react(IJasimAppContext context, JasimModel model,
			Event event, CustomReaction reaction) throws Exception {
		IEventSimulationInfoProvider simulatorInfo = context.getService(IEventSimulationInfoProvider.class);
		if (simulatorInfo != null) {
			for (SolutionSimulator.Agent ag: simulatorInfo.getSimulator().agents)
				if (ag.isInconsistence()) {
					simulatorInfo.getSimulator().getModel().setInconsistent(true);
					break;
				}
		}
		return false;
	}

}
